package com.example.rwq_test.designParttern.multiThread.WorkerThread;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * 工作请求
 *
 * @author renweiqiang
 * @version 1.0.0
 * @createTime 2022/11/3
 */
public class Request {
    /**
     * 委托者
     */
    private final String name;
    /**
     * 请求的编号
     */
    private final int number;
    private static final Random random = new Random();

    public Request(String name, int number) {
        this.name = name;
        this.number = number;
    }

    public void execute() {
        try {
            System.out.println(Thread.currentThread().getName() + " executes " + this);
            TimeUnit.MILLISECONDS.sleep(random.nextInt(100));
        } catch (InterruptedException e) {

        }
    }

    public String toString() {
        return "[ Request from " + name + " No." + number + " ]";
    }
}
